from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-26 14:02:17.060702
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 26, Apr, 2022
Time: 14:02:22
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.0903
Nobs: 638.000 HQIC: -49.4750
Log likelihood: 7802.88 FPE: 2.55409e-22
AIC: -49.7192 Det(Omega_mle): 2.22048e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.328575 0.062204 5.282 0.000
L1.Burgenland 0.104886 0.039451 2.659 0.008
L1.Kärnten -0.110538 0.020687 -5.343 0.000
L1.Niederösterreich 0.195052 0.082503 2.364 0.018
L1.Oberösterreich 0.120226 0.081353 1.478 0.139
L1.Salzburg 0.258746 0.041901 6.175 0.000
L1.Steiermark 0.044589 0.055113 0.809 0.418
L1.Tirol 0.104515 0.044582 2.344 0.019
L1.Vorarlberg -0.064889 0.039349 -1.649 0.099
L1.Wien 0.025027 0.072124 0.347 0.729
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052220 0.133050 0.392 0.695
L1.Burgenland -0.035057 0.084382 -0.415 0.678
L1.Kärnten 0.041050 0.044248 0.928 0.354
L1.Niederösterreich -0.196987 0.176469 -1.116 0.264
L1.Oberösterreich 0.452152 0.174009 2.598 0.009
L1.Salzburg 0.285487 0.089624 3.185 0.001
L1.Steiermark 0.108113 0.117882 0.917 0.359
L1.Tirol 0.309472 0.095359 3.245 0.001
L1.Vorarlberg 0.023894 0.084165 0.284 0.776
L1.Wien -0.031658 0.154268 -0.205 0.837
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190144 0.031837 5.973 0.000
L1.Burgenland 0.089991 0.020191 4.457 0.000
L1.Kärnten -0.007796 0.010588 -0.736 0.462
L1.Niederösterreich 0.246322 0.042226 5.833 0.000
L1.Oberösterreich 0.159039 0.041637 3.820 0.000
L1.Salzburg 0.040729 0.021445 1.899 0.058
L1.Steiermark 0.026493 0.028207 0.939 0.348
L1.Tirol 0.085371 0.022818 3.741 0.000
L1.Vorarlberg 0.054053 0.020139 2.684 0.007
L1.Wien 0.117237 0.036914 3.176 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111285 0.031950 3.483 0.000
L1.Burgenland 0.044585 0.020263 2.200 0.028
L1.Kärnten -0.013756 0.010626 -1.295 0.195
L1.Niederösterreich 0.177258 0.042376 4.183 0.000
L1.Oberösterreich 0.330400 0.041786 7.907 0.000
L1.Salzburg 0.101483 0.021522 4.715 0.000
L1.Steiermark 0.111816 0.028308 3.950 0.000
L1.Tirol 0.094523 0.022899 4.128 0.000
L1.Vorarlberg 0.059807 0.020211 2.959 0.003
L1.Wien -0.018083 0.037045 -0.488 0.625
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.113509 0.059604 1.904 0.057
L1.Burgenland -0.044221 0.037801 -1.170 0.242
L1.Kärnten -0.045811 0.019822 -2.311 0.021
L1.Niederösterreich 0.140658 0.079055 1.779 0.075
L1.Oberösterreich 0.160492 0.077952 2.059 0.040
L1.Salzburg 0.283816 0.040150 7.069 0.000
L1.Steiermark 0.057760 0.052809 1.094 0.274
L1.Tirol 0.162350 0.042719 3.800 0.000
L1.Vorarlberg 0.097442 0.037704 2.584 0.010
L1.Wien 0.076365 0.069109 1.105 0.269
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059629 0.046889 1.272 0.203
L1.Burgenland 0.029127 0.029738 0.979 0.327
L1.Kärnten 0.052182 0.015594 3.346 0.001
L1.Niederösterreich 0.201999 0.062191 3.248 0.001
L1.Oberösterreich 0.326592 0.061324 5.326 0.000
L1.Salzburg 0.038095 0.031585 1.206 0.228
L1.Steiermark 0.008576 0.041544 0.206 0.836
L1.Tirol 0.126346 0.033606 3.760 0.000
L1.Vorarlberg 0.064326 0.029661 2.169 0.030
L1.Wien 0.094121 0.054366 1.731 0.083
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172270 0.056189 3.066 0.002
L1.Burgenland 0.005910 0.035636 0.166 0.868
L1.Kärnten -0.065720 0.018687 -3.517 0.000
L1.Niederösterreich -0.100392 0.074526 -1.347 0.178
L1.Oberösterreich 0.205496 0.073487 2.796 0.005
L1.Salzburg 0.055647 0.037850 1.470 0.142
L1.Steiermark 0.241635 0.049784 4.854 0.000
L1.Tirol 0.502022 0.040272 12.466 0.000
L1.Vorarlberg 0.062188 0.035545 1.750 0.080
L1.Wien -0.076455 0.065150 -1.174 0.241
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.146329 0.062301 2.349 0.019
L1.Burgenland 0.002493 0.039512 0.063 0.950
L1.Kärnten 0.061415 0.020719 2.964 0.003
L1.Niederösterreich 0.176023 0.082632 2.130 0.033
L1.Oberösterreich -0.055810 0.081480 -0.685 0.493
L1.Salzburg 0.207973 0.041967 4.956 0.000
L1.Steiermark 0.137644 0.055199 2.494 0.013
L1.Tirol 0.062045 0.044652 1.390 0.165
L1.Vorarlberg 0.146468 0.039411 3.716 0.000
L1.Wien 0.117576 0.072236 1.628 0.104
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.377678 0.036741 10.279 0.000
L1.Burgenland -0.002000 0.023302 -0.086 0.932
L1.Kärnten -0.021277 0.012219 -1.741 0.082
L1.Niederösterreich 0.208983 0.048732 4.288 0.000
L1.Oberösterreich 0.228721 0.048052 4.760 0.000
L1.Salzburg 0.038652 0.024749 1.562 0.118
L1.Steiermark -0.012672 0.032553 -0.389 0.697
L1.Tirol 0.091830 0.026333 3.487 0.000
L1.Vorarlberg 0.052726 0.023242 2.269 0.023
L1.Wien 0.039625 0.042601 0.930 0.352
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035864 0.111852 0.172784 0.139857 0.101673 0.083127 0.036314 0.209486
Kärnten 0.035864 1.000000 -0.022785 0.132550 0.051325 0.088430 0.442960 -0.063798 0.090945
Niederösterreich 0.111852 -0.022785 1.000000 0.320946 0.127751 0.282235 0.072873 0.158863 0.295188
Oberösterreich 0.172784 0.132550 0.320946 1.000000 0.219511 0.306608 0.169397 0.144275 0.245348
Salzburg 0.139857 0.051325 0.127751 0.219511 1.000000 0.129773 0.095775 0.109053 0.127689
Steiermark 0.101673 0.088430 0.282235 0.306608 0.129773 1.000000 0.139908 0.115963 0.044923
Tirol 0.083127 0.442960 0.072873 0.169397 0.095775 0.139908 1.000000 0.067234 0.150608
Vorarlberg 0.036314 -0.063798 0.158863 0.144275 0.109053 0.115963 0.067234 1.000000 0.000978
Wien 0.209486 0.090945 0.295188 0.245348 0.127689 0.044923 0.150608 0.000978 1.000000